<template>
  <div 
    class="department-card" 
    :class="{ 'best-recommendation': isBest }"
    @click="viewDetails"
  >
    <div class="card-badge" v-if="isBest">
      <el-tag type="danger" effect="dark">最佳推荐</el-tag>
    </div>
    
    <div class="card-content">
      <div class="department-header">
        <div class="department-icon">
          <el-icon><OfficeBuilding /></el-icon>
        </div>
        <div class="department-info">
          <h3 class="department-name">{{ department.name }}</h3>
          <div class="match-rate">
            <el-progress 
              :percentage="department.matchRate" 
              :show-text="false" 
              :stroke-width="6"
            />
            <span class="match-text">匹配度 {{ department.matchRate }}%</span>
          </div>
        </div>
      </div>
      
      <div class="department-details">
        <div class="detail-item">
          <el-icon><Timer /></el-icon>
          <span>当前排队: {{ department.waiting }}人</span>
        </div>
        <div class="detail-item">
          <el-icon><Clock /></el-icon>
          <span>预计等待: {{ department.waitTime }}</span>
        </div>
        <div class="detail-item">
          <el-icon><User /></el-icon>
          <span>值班医生: {{ department.doctors.join('、') }}</span>
        </div>
      </div>
      
      <div class="recommendation-reason">
        <p>{{ department.reason }}</p>
      </div>
      
      <div class="card-actions">
        <el-button 
          type="primary" 
          @click.stop="makeAppointment"
        >
          预约挂号
        </el-button>
        <el-button 
          @click.stop="viewDetails"
        >
          科室详情
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ElTag, ElIcon, ElProgress, ElButton, ElMessage } from 'element-plus'
import { OfficeBuilding, Timer, Clock, User } from '@element-plus/icons-vue'

const props = defineProps({
  department: {
    type: Object,
    required: true
  },
  isBest: {
    type: Boolean,
    default: false
  }
})

const emit = defineEmits(['appointment', 'details'])

const makeAppointment = () => {
  emit('appointment', props.department)
  ElMessage.success(`已选择预约${props.department.name}`)
}

const viewDetails = () => {
  emit('details', props.department)
}
</script>

<style scoped>
.department-card {
  position: relative;
  border: 1px solid #ebeef5;
  border-radius: 8px;
  padding: 20px;
  background: #fff;
  transition: all 0.3s;
  cursor: pointer;
  overflow: hidden;
}

.department-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.department-card.best-recommendation {
  border-color: #f56c6c;
  border-width: 2px;
}

.card-badge {
  position: absolute;
  top: -10px;
  right: 10px;
  z-index: 1;
}

.department-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}

.department-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #ecf5ff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  color: #409eff;
  font-size: 24px;
}

.department-info {
  flex: 1;
}

.department-name {
  margin: 0 0 8px 0;
  font-size: 18px;
  color: #333;
}

.match-rate {
  display: flex;
  align-items: center;
  gap: 10px;
}

.match-text {
  font-size: 14px;
  color: #666;
}

.department-details {
  margin-bottom: 16px;
}

.detail-item {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
  color: #666;
}

.detail-item .el-icon {
  margin-right: 8px;
  color: #409eff;
}

.recommendation-reason {
  padding: 12px;
  background: #f5f7fa;
  border-radius: 4px;
  margin-bottom: 16px;
  font-size: 14px;
  color: #666;
}

.card-actions {
  display: flex;
  gap: 12px;
}

.card-actions .el-button {
  flex: 1;
}
</style>